//
//  XJCommunityHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/30.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJCommunityHeaderView.h"

@interface XJCommunityHeaderView()
@property(nonatomic, strong) UIImageView *bgImageView;
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *nameLabel; // 社区名字label
@property(nonatomic, strong) UILabel *addressLabel; // 地址Label
@end

@implementation XJCommunityHeaderView


#pragma mark - 一初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView{
    [self addSubview:self.bgImageView];
    [self.bgImageView addSubview:self.iconIv];
    [self.bgImageView addSubview:self.nameLabel];
    [self.bgImageView addSubview:self.addressLabel];
}

#pragma mark - 二 lazy
- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
    }
    return _bgImageView;
}

- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
        _iconIv.image = [UIImage imageNamed:@"my_wallet"]; // 没图 先占位
    }
    return _iconIv;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor whiteColor];
    }
    return _nameLabel;
}
- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.numberOfLines = 0;
        _addressLabel.textColor = [UIColor whiteColor];
    }
    return _addressLabel;
}

#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgImageView.mas_left).offset(15);
        make.size.mas_equalTo(CGSizeMake(60, 60));
        make.centerY.equalTo(self.bgImageView.mas_centerY);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(5);
        make.right.equalTo(self.bgImageView.mas_right);
        make.top.equalTo(self.iconIv.mas_top).offset(5);
        make.height.mas_equalTo(20);
    }];
    
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(5);
        make.right.equalTo(self.bgImageView.mas_right);
        make.bottom.equalTo(self.iconIv.mas_bottom);
        make.height.mas_equalTo(20);
    }];
}



- (void)configureBgImageStr:(NSString *)imgStr iconStr:(NSString *)iconStr name:(NSString *)name address:(NSString *)address {
    UIImage *defalultImg = [UIImage imageNamed:@"default_goods"];
    
    [self.bgImageView sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:defalultImg];
    
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:iconStr] placeholderImage:defalultImg];
    
    self.nameLabel.text = name;
    self.addressLabel.text = [NSString stringWithFormat:@"地址:%@",address];
}

- (void)reConfigureName:(NSString *)name address:(NSString *)address {
    self.nameLabel.text = name;
    self.addressLabel.text = [NSString stringWithFormat:@"地址:%@",address];
}
@end
